<?php
/**
 * Created by PhpStorm.
 * User: xuzhong
 * Date: 2025/4/2
 * Time: 13:49
 */

namespace app\api\service;

use app\admin\model\Partner as PartnerModel;
use app\api\model\Images;
use app\facade\Basic;
use ZipStream\Test\Zip64\DataDescriptorTest;

class Partner
{

    protected $model;

    public function __construct()
    {
        $this->model = new PartnerModel();

    }

    /**
     * @describe 获取合作伙伴列表
     * @author: 徐众
     * @date: 2025-04-02 13:02:26
     * @param [] type
     * @return Renderable
     */
    public function getList(): array
    {

        #处理查询条件
        $where = ['is_del' => 0];
        $sql = $this->model->where($where);
        #取数据
        $list = $sql->field('name,image,link,description')->order('sort ASC')->select()->toArray();
        if (!$list) {
            return Basic::data(0, 'common.success', []);
        }
        $photoId = array_unique(array_column($list,'image'));
        #获取图片url
        $oImages = new Images();
        $photoUrls = $oImages->getImagesByIds($photoId);
        $avatorUrls = array_column($photoUrls, null, 'id');
        #替换url
        foreach ($list as $k=>$v){
            $list[$k]['image'] = $avatorUrls[$v['image']]['url']??'';

        }

        return Basic::data(0, 'common.success',$list);
    }

}